<?php

require __DIR__ . '/../autoload.php';

use Agi\Config\Mail;

/**
 * Created by PhpStorm.
 * User: Janpoem
 * Date: 2015/3/10
 * Time: 2:55
 */
class TestMail extends PHPUnit_Framework_TestCase
{

    private function getConfigData1()
    {
        return array(
            'host'     => 'stmp.gmail.com',
            'username' => 'test',
            'password' => 'test',
            'smtp'     => Mail::USE_SSL, // 465
            'from'     => 'ok:janpoem@gmail.com'
        );
    }

    public function testEmailConfig1()
    {
        $data = $this->getConfigData1();
        // 注册一个Email配置
        Mail::define($data);
        // 取回这个配置
        /** @var Mail $config */
        $config = Mail::get();

        foreach ($data as $field => $value) {
            if ($field === 'from') {
                $this->assertEquals("{$config->fromName}:{$config->fromMail}", $value);
            } else {
                $this->assertEquals($config->$field, $value);
            }
        }

        $this->assertEquals($config->port, 465);
    }

    public function testObjectCompare()
    {
        $data = $this->getConfigData1();
        Mail::defineMulti(array(
            'test1' => array(

            ),
            'test2' => array(

            )
        ));

        $loadConfig = Mail::get('test1');
        $conf1 = Mail::get('test1');
        $conf2 = Mail::get('test2');

        // loadConfig应该是conf1
        $this->assertEquals($conf1, $loadConfig);

        // loadConfig不应该是conf2
        $this->assertNotEquals($conf2, $loadConfig);
    }
}
